/* Signlink - Decompiled by JODE
 * Visit http://jode.sourceforge.net/
 */
import java.applet.Applet;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URL;

public class Signlink implements Runnable {
	public static Method aMethod398;
	public Resource aClass56_399;
	public String cacheDirectory = null;
	public static String aString401;
	public String aString402;
	public String aString403 = null;
	public Interface3 anInterface3_404;
	public Thread aThread405;
	public boolean aBoolean406;
	public static String aString407;
	public String aString408;
	public Runnable_Impl1 aRunnable_Impl1_409;
	public int anInt410;
	public LocalFile childFileTableFile;
	public Resource aClass56_412;
	public LocalFile cacheDataFile;
	public static String aString414;
	public static int anInt415 = 3;
	public Applet anApplet416;
	public static Method aMethod417;
	public InetAddress anInetAddress418;
	public LocalFile[] cacheIndexFiles;

	public Resource method249(byte i, URL url) {
		return method254(0, 4, 0, url, (byte) 38);
	}

	public void run() {
		for (;;) {
			Resource class56;
			synchronized (this) {
				for (;;) {
					if (aBoolean406)
						return;
					if (aClass56_399 != null) {
						class56 = aClass56_399;
						aClass56_399 = aClass56_399.linkedResource;
						if (aClass56_399 == null)
							aClass56_412 = null;
						break;
					}
					try {
						this.wait();
					} catch (InterruptedException interruptedexception) {
						/* empty */
					}
				}
			}
			try {
				int i = class56.type;
				if (i == 1)
					class56.resource = new Socket(anInetAddress418, class56.value);
				else if (i != 2) {
					if (i == 4)
						class56.resource = new DataInputStream(((URL) class56.base).openStream());
					else if (i == 9) {
						Object[] objects = (Object[]) class56.base;
						class56.resource = (((Class) objects[0]).getDeclaredMethod((String) objects[1], (Class[]) objects[2]));
					} else if (i == 10) {
						Object[] objects = (Object[]) class56.base;
						class56.resource = ((Class) objects[0]).getDeclaredField((String) objects[1]);
					} else
						throw new Exception();
				} else {
					Thread thread = new Thread((Runnable) class56.base);
					thread.setDaemon(true);
					thread.start();
					thread.setPriority(class56.value);
					class56.resource = thread;
				}
				class56.state = 1;
			} catch (Exception exception) {
				class56.state = 2;
			}
		}
	}

	public Interface3 method250(byte i) {
		return anInterface3_404;
	}

	public Runnable_Impl1 method251(int i) {
		return aRunnable_Impl1_409;
	}

	public Resource method252(int i, Runnable runnable, int i_0_) {
		return method254(0, 2, i_0_, runnable, (byte) 122);
	}

	public void getCacheLocation(String string, int i, int i_1_) {
		if ((i_1_ ^ 0xffffffff) > i || i_1_ > 34)
			i_1_ = 32;
		if (aString414 == null)
			aString414 = "~/";
		String[] strings = { "cache", "bin/cache" };
		for (int i_3_ = 0; strings.length > i_3_; i_3_++) {
			try {
				String string_4_ = strings[i_3_];
				if (string_4_.length() > 0) {
					File file = new File(string_4_);
					if (!file.exists())
						continue;
				}
				File file = new File(string_4_);
				if (file.exists() || file.mkdir()) {
					if (string.length() > 0) {
						//file = new File(file, string);
						if (!file.exists() && !file.mkdir())
							continue;
					}
					aString408 = aString403 = file.getParent() + "/";
					aString402 = cacheDirectory = file.getPath() + "/";
					return;
				}
			} catch (Exception exception) {
				/* empty */
			}
		}
		throw new RuntimeException();
	}

	public Resource method254(int i, int i_5_, int i_6_, Object object, byte i_7_) {
		Resource class56 = new Resource();
		class56.base = object;
		if (i_7_ < 25)
			return null;
		class56.type = i_5_;
		class56.value = i_6_;
		synchronized (this) {
			if (aClass56_412 != null) {
				aClass56_412.linkedResource = class56;
				aClass56_412 = class56;
			} else
				aClass56_412 = aClass56_399 = class56;
			this.notify();
		}
		return class56;
	}

	public Resource method255(int i, int i_8_) {
		if (i_8_ != 4)
			readUID(true);
		return method254(0, 1, i, null, (byte) 108);
	}

	public Resource method256(int i, int i_9_) {
		if (i_9_ != 0)
			method254(-127, -76, -46, null, (byte) -27);
		return method254(0, 3, i, null, (byte) 92);
	}

	public void method257(byte i) {
		synchronized (this) {
			aBoolean406 = true;
			this.notifyAll();
		}
		try {
			aThread405.join();
		} catch (InterruptedException interruptedexception) {
			/* empty */
		}
		if (aRunnable_Impl1_409 != null)
			aRunnable_Impl1_409.method6((byte) 72);
		if (cacheDataFile != null) {
			try {
				cacheDataFile.close();
			} catch (IOException ioexception) {
				/* empty */
			}
		}
		if (childFileTableFile != null) {
			try {
				childFileTableFile.close();
			} catch (IOException ioexception) {
				/* empty */
			}
		}
		if (cacheIndexFiles != null) {
			for (int i_10_ = 0; cacheIndexFiles.length > i_10_; i_10_++) {
				if (cacheIndexFiles[i_10_] != null) {
					try {
						cacheIndexFiles[i_10_].close();
					} catch (IOException ioexception) {
						/* empty */
					}
				}
			}
		}
	}

	public Resource method258(byte i, String string, Class[] var_classes, Class var_class) {
		return method254(0, 9, 0, new Object[] { var_class, string, var_classes }, (byte) 50);
	}

	public void readUID(boolean bool) {
		try {
			if (bool)
				anApplet416 = null;
			File file = new File(aString403 + "uid.dat");
			if (!file.exists() || file.length() < 4L) {
				DataOutputStream dataoutputstream = new DataOutputStream(new FileOutputStream(aString403 + "uid.dat"));
				dataoutputstream.writeInt((int) (Math.random() * 9.9999999E7));
				dataoutputstream.close();
			}
		} catch (Exception exception) {
			/* empty */
		}
		try {
			DataInputStream datainputstream = new DataInputStream(new FileInputStream(aString403 + "uid.dat"));
			anInt410 = datainputstream.readInt() + 1;
			datainputstream.close();
		} catch (Exception exception) {
			/* empty */
		}
	}

	public Resource method260(byte i) {
		return null;
	}

	public Resource method261(Class var_class, String string, int i) {
		return method254(0, 10, 0, new Object[] { var_class, string }, (byte) 107);
	}

	public Signlink(boolean bool, Applet applet, InetAddress inetaddress, int i, String string, int i_11_) throws IOException {
		aString402 = null;
		aClass56_399 = null;
		aClass56_412 = null;
		aString408 = null;
		aBoolean406 = false;
		cacheDataFile = null;
		anApplet416 = null;
		anInt410 = 0;
		childFileTableFile = null;
		aString401 = "Unknown";
		aString407 = "1.1";
		anApplet416 = applet;
		anInetAddress418 = inetaddress;
		try {
			aString401 = System.getProperty("java.vendor");
			aString407 = System.getProperty("java.version");
			aString414 = System.getProperty("user.home");
			if (aString414 != null)
				aString414 += "/";
		} catch (Exception exception) {
			/* empty */
		}
		try {
			if (applet == null)
				aMethod398 = (Class.forName("java.awt.Component").getDeclaredMethod("setFocusTraversalKeysEnabled", new Class[] { Boolean.TYPE }));
			else
				aMethod398 = (applet.getClass().getMethod("setFocusTraversalKeysEnabled", new Class[] { Boolean.TYPE }));
		} catch (Exception exception) {
			/* empty */
		}
		try {
			if (applet == null)
				aMethod417 = (Class.forName("java.awt.Container").getDeclaredMethod("setFocusCycleRoot", new Class[] { Boolean.TYPE }));
			else
				aMethod417 = applet.getClass().getMethod("setFocusCycleRoot", (new Class[] { Boolean.TYPE }));
		} catch (Exception exception) {
			/* empty */
		}
		if (bool) {
			getCacheLocation(string, -33, i);
			cacheDataFile = new LocalFile(new File(cacheDirectory + "main_file_cache.dat2"), "rw", 52428800L);
			cacheIndexFiles = new LocalFile[i_11_];
			for (int i_12_ = 0; i_11_ > i_12_; i_12_++)
				cacheIndexFiles[i_12_] = new LocalFile(new File(cacheDirectory + "main_file_cache.idx" + i_12_), "rw", 1048576L);
			childFileTableFile = new LocalFile(new File(cacheDirectory + "main_file_cache.idx255"), "rw", 1048576L);
			readUID(false);
		}
		aBoolean406 = false;
		aThread405 = new Thread(this);
		aThread405.setPriority(10);
		aThread405.setDaemon(true);
		aThread405.start();
	}
}
